<?php


class OWOX_Functions_IntraTestHelper extends OWOX_Functions_BaseFunctions
{
    public $url = 'http://www.intra.owox.com.ll';
    public $scheduler = 'http://my.intra.owox.com.ll/scheduler/';
    public $field_login = '//*[@id="autorization-mail"]';
    public $field_password = '//*[@id="autorization-pass"]';
    public $button_submit = '//*[@id="form_auth"]/span[1]/input';
    public $button_exit = '//button[@type="submit"]';
    public $user = 'o.krasovsky';
    public $password = '123321';

    public function setCurrentUrl($suff = null) {
       return $url = $this -> url . $suff;
    }

    /**
     * @param $user
     * @param $password
     * @return void
     */

    public function loginIntra($user, $password)
    {
        $this -> openPage($this ->url);
        $this -> fillField($this -> field_login, $user);
        $this -> fillField($this -> field_password, $password);
        $this -> pressButtonAndWait($this -> button_submit, 1000);
        $this -> isLoggedIntra();
    }


    /**
     * @return void
     */

    public function logoutIntra() {
        if ($this -> isLoggedIntra() == true){
            $this -> pressButton($this -> button_exit);
        }
        $this -> isNotLoggedIntra();
    }

    /**
     * @return boolean
     */

    public function isLoggedIntra(){
        $find_exit = $this -> _findElement($this -> button_exit);
        if ($find_exit !== null) {
            return true;
        }
    }

    /**
     * @return boolean
     */

    public function isNotLoggedIntra(){
        $find_menu = $this -> _findElement($this -> field_password);
        if ($find_menu == null){
            return true;
        }
    }





    public function switchInScheduler ($frame) {
        $scheduler = 'http://my.intra.owox.com.ll/scheduler/';
        $day_off = '#tab=daysoff';
        $hosp = '#tab=hospitals';
        $business = '#tab=businesstrips';
        $vacation = '#tab=vacations';
        switch ($frame) {
            case 'dayoff':
                return $scheduler . $day_off;
                break;
            case 'hosp':
                return $scheduler . $hosp;
                break;
            case 'business':
                return $scheduler . $business;
                break;
            case 'vacation':
                return $scheduler . $vacation;
                break;
            default:
                return $scheduler;
        }


    }



    public function changeScheduler ($start_time, $end_time) {

        $this -> pressButton('//*[@id="show_edit_scheduler"]');

        $fields = array (
        0 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[1]/td[3]/input',
        1 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[2]/td[3]/input',
        2 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[3]/td[3]/input',
        3 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[4]/td[3]/input',
        4 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[5]/td[3]/input',
        5 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[1]/td[4]/input',
        6 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[2]/td[4]/input',
        7 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[3]/td[4]/input',
        8 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[4]/td[4]/input',
        9 => '//*[@id="edit_scheduler"]/div/form/table/tbody/tr[5]/td[4]/input',

    );

        for ($i = 0; $i < 5; $i++) {
            $this -> fillField($fields[$i], $start_time);
        }

        for ($i = 5; $i < 10; $i++) {
            $this -> fillField($fields[$i], $end_time);
        }

        $this -> pressButton('//*[@id="edit_scheduler"]/div/form/span/input');
        $this -> session -> wait(2500);
        $this -> textValidation('//*[@id="app-message"]/div', 'Расписание успешно изменено', 'Ошибка подтверждения');
    }

}

